var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.json( { code:200,data:null,msg:"欢迎访问小u课堂API v1.0" });
});
//轮播图接口
router.get("/banner",async (req,res)=>{
  let sql=`select id,CONCAT('/uploads/',image_src) as  image_src,title from e_banners where isshow=1`;
  // `select * from e_banners where isshow =1`;
  let a = await db.query(sql,[]);
  res.json({
    code:200,data:a,msg:"轮播图数据成功"
  }); 
})
//首页列表接口
router.get("/courselist",async(req,res)=>{
  let {type=1,num=8} =req.query;
  let sql=`select id,cid,title,price,CONCAT('/uploads/course/', image_src) as image_src,type_name,area_name,grade_name,subject_name,category_name from e_course where type=${type} limit 0,${num}`;
  let a=await db.query(sql,[]);
  res.json({code:200,data:a,msg:"首页课程列表数据成功"})
})

module.exports = router;
